##首先读取文件美国，日本，印度.txt
import json

import opts
from pyecharts.charts import Line
from pyecharts.options import TitleOpts, LegendOpts, ToolboxOpts, VisualMapOpts, LabelOpts

with open('D:/美国.txt','r',encoding='utf-8')as us_f:
    us_f = us_f.read()
    us_f = us_f.replace("jsonp_1629344292311_69436(", '')
    us_f = us_f[:-2:]
    # 将json 转python文件
    us_f_j = json.loads(us_f)
    # 懒人网看层级
    us_f_j = us_f_j['data'][0]['trend']
    # 获取确诊的三条数据
    us_data_y = us_f_j['list'][0]['data']

with open('D:/日本.txt', 'r', encoding='utf-8')as jp_f:
    jp_f = jp_f.read()
    jp_f = jp_f.replace("jsonp_1629350871167_29498(", '')
    jp_f = jp_f[:-2:]

    jp_f_j = json.loads(jp_f)
    jp_f_j = jp_f_j['data'][0]['trend']
    jp_data_y = jp_f_j['list'][0]['data']

with open('D:/印度.txt', 'r', encoding='utf-8')as ld_f:
    ld_f = ld_f.read()
    ld_f = ld_f.replace("jsonp_1629350745930_63180(", '')
    ld_f = ld_f[:-2:]
    # 将json 转python文件
    ld_f_j = json.loads(ld_f)
    # 懒人网看层级
    ld_f_j = ld_f_j['data'][0]['trend']
    # 获取确诊的三条数据

    ld_data_y = ld_f_j['list'][0]['data']


#x轴是公用的，所以取一个就行
x_data=us_f_j['updateDate']
x_data=x_data[:315:]


line=Line()
#x轴
line.add_xaxis(x_data)
#y轴
line.add_yaxis('印度确诊人数',
               ld_data_y,
               label_opts=LabelOpts(is_show=False))



line.add_yaxis('美国确诊人数',
               us_data_y,
               label_opts=LabelOpts(is_show=False))


line.add_yaxis('日本确诊人数',
               jp_data_y,
               label_opts=LabelOpts(is_show=False),
               )





#全局设置
line.set_global_opts(
    title_opts =TitleOpts(title="确诊人数展示",pos_left='center',pos_bottom='1%'),#标题，位置控制
    legend_opts=LegendOpts(is_show=True),#图列，表示。is_show=True 是否展示
    toolbox_opts=ToolboxOpts(is_show=True),#工具箱，
    visualmap_opts=VisualMapOpts(is_show=True) #视觉映射的选项

)
#生成
line.render()


#关闭文件
